//观察者模式

const list:Set<Function> = new Set()

const autorun = (cb:Function) => {
  if(!list.has(cb)){
    list.add(cb)
  }
}

const observable = <T extends object>(param:T)=>{
  return new Proxy(param,{
    set(target,key,value,receiver){
      const result = Reflect.set(target,key,value,receiver)
      list.forEach(fn => fn())
      return result;
    }
  })
}

const personProxy = observable({
  name:'张三',
  age:18
})

autorun(()=>{
  console.log("有变化了",personProxy)
})

personProxy.age = 12
